import ajax from '@/utils/ajax'
let _this_;
const getData = () => _this_.curData || _this_.curData;
const getLoading = () => _this_.loading || _this_.loading;
let deptNameCheck = (rule, value, callback)=> {
    _this_.$ajax.get(_this_.$api.system.dept.checkDeptName,{deptName:getData().deptName,id:getData().id}).then(result => {
        if(result.bean>0) {
            callback("部门名称已存在");
        } else {
            callback();
        }
    }).catch(error => {
        callback("获取部门名称异常");
    });
}
let deptParentIdCheck = (rule, value, callback)=> {
    _this_.$ajax.get(_this_.$api.system.dept.checkParentId,{parentId:getData().parentId,id:getData().id}).then(result => {
        if(result.bean>0) {
            callback("父类不能选择子节点或当前节点");
        } else {
            callback();
        }
    }).catch(error => {
        callback("父类不能选择子节点或当前节点");
    });
}
export default (context) => {
    _this_ = context;
    return {
        parentId: [
            {required: true, message: '请选择父部门', trigger: 'blur'},
            {validator: deptParentIdCheck, trigger: 'blur'}
        ],
        type: [
            {required: true, message: '请选择部门类型', trigger: 'blur'},
        ],
        deptName: [
            {required: true, message: '请输入名称', trigger: 'blur'},
            {min: 3, max: 25, message: '长度在 3 到 20 个字符', trigger: 'blur'},
            {validator: deptNameCheck, trigger: 'blur'},
        ],
        sort: [
            {required: true, message: '请输入排序', trigger: 'blue'},
            {pattern: /^[0-9]{1,3}$/, message: '必须为数字范围0到999', trigger: 'blue'},
        ]
    }
}
